var t1;
var remianTimerFun
///倒计时,参数为秒,unity 调用
function RemianTime(remianTime)
{
	isFire = false;
	StartShow(remianTime);
}

function StartShow(remianTime)
{
	remianTime = remianTime/60;
	t1 = new Date();
	t1 = new Date(t1.valueOf() + (60 * 1000 * remianTime));

	remianTimerFun=setInterval(CallTime,1000);
}

var isFire = false;
function RemainFireTime(remianFireTime)
{
	isFire = true;
	RemoveRemianTimer();
	StartShow(remianFireTime);
}

function CallTime(){
	//var t1="2020/02/27 22:00"
	if(new Date(t1)-new Date()<=0){
	   RemoveRemianTimer();
	   if(!isFire)
	   {
		   app.timeShow = "游戏已结束";
	   }
	   else
	   {
		   app.timeShow = "即将开火";
	   }
	  
	  //alert('计时完成');
	}else{
	  var h=cd(t1, new Date(), 'h');
	  var m=cd(t1, new Date(), 'm');
	  var s=cd(t1, new Date(), 's');
	  
	  var totalM = m+h*60;
	  if(s<=9)
	  {
		  s = "0"+s;
	  }
	  
	  if(m<=9)
	  {
	  	  m = "0"+m;
	  }
	  
	  if(totalM<=9)
	  {
	  	  totalM = "0"+totalM;
	  }
	  
	  if(!isFire)
	  {
		   app.timeShow = "游戏剩时："+totalM+'分'+s+'秒';
	  }
	  else
	  {
		  app.timeShow = "开火剩时："+m+'分'+s+'秒';
	  }
	 
	}
}
function RemoveRemianTimer()
{
	window.clearInterval(remianTimerFun);
}
		
	/*
	2017-01-04 by xw
	获取倒计时 返回值数字
	
	t1 开始时 时间格式
	t2 结束时 时间格式
	tg 要获取的值 字符串
	  h 时
	  m 分
	  s 秒
	*/
	function cd(t1, t2, tg) {
		//相差的毫秒数
		var ms = Date.parse(t1) - Date.parse(t2);
		var minutes = 1000 * 60;
		var hours = minutes * 60;
		
		//求出除开天数，剩余的毫秒数
	  
		var h = Math.floor(ms / hours);
		ms %= hours;
		var m = Math.floor(ms / minutes);
		ms %= minutes;
		var s = Math.floor(ms / 1000);
		//返回所需值并退出函数
		switch(tg){
		  case 'h' : return h;
		  case 'm' : return m;
		  case 's' : return s;
		}
	}